import { Button, View } from "@tarojs/components"
import Taro from "@tarojs/taro"



const Information = props => {

    // 管理员认证成功后会改变该用户在login表中的用户类型，并保留在营养师表中enroll
    const handleChange = openid => {
        console.log("认证通过:", openid)

        Taro.cloud.callFunction({
            name: "enroll",
            data: {
                $url: "updateOccupation",
                openid: openid
            }
        }).then(() => {
            //触发事件循环，进行路由跳转操作
            Taro.showToast({
                title: '认证成功',
                icon: 'success',
                duration: 2000,
                success() {
                    //弹窗后执行，可以省略
                    setTimeout(()=>{
                        Taro.reLaunch({
                            url: '/pages/my/auditing/message',
                        })
                    }, 1500);
                }
            })

        })
    }
    // 管理员认证失败后就会从营养师表（enroll）中删除该用户的注册信息
    const handleRomve = openid => {
        console.log("撤回认证:", openid)
        Taro.cloud.callFunction({
            name: "enroll",
            data: {
                $url: "removeOccupation",
                openid: openid
            }
        }).then(res => {
            Taro.showToast({
                title: '认证成功',
                icon: 'error',
                duration: 2000,
                success() {
                    //触发事件循环，进行路由跳转操作
                    setTimeout(()=>{
                        Taro.reLaunch({
                            url: '/pages/my/auditing/message',
                        })
                    }, 1500);
                }
            })
            return;
        })
    }
    return (
        <View>
            <View className="box2">
                <Button className="box21" formType='submit' onClick={() => handleChange(props.openid)}>通过</Button>
                <Button className="box22" formType='reset' onClick={() => handleRomve(props.openid)}>撤回</Button>
            </View>
            {/* <Button onClick={}>认证</Button>
            <Button onClick={handleRomve}>撤回</Button> */}
        </View>
    )
}

export default Information
